package fr.ginvest.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity implementation class for Entity: Article
 *
 */
@Entity
@Table(name = "article")
public class Article implements Serializable {
  
	public enum Visibilite {PUBLIC,TOUT_PUBLIC}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@Column(length=120)
	private String titre;
	
	@Column(length=5000)
	private String description;
	
	@Column(length=5000)
	private String resume;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="id_investisseur", referencedColumnName="id", nullable=false)
	private Investisseur investisseur;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "article")
	private Set<Commentaire>  commentaires = new HashSet<Commentaire>();
	
	@Temporal(TemporalType.DATE)
	private java.util.Date dateCreation;
	
	@Enumerated(EnumType.STRING)
	@Column(length=12, nullable=false)
	private Visibilite visibilite;
	
	private static final long serialVersionUID = 1L;

	public Article() {
		super();
	}   
	public Article(String titre) {
		super();
		this.titre = titre;
		this.visibilite = Visibilite.PUBLIC;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}
   
	public java.util.Date getDateCreation() {
		return dateCreation;
	}
	
	public void setDateCreation(java.util.Date dateCreation) {
		this.dateCreation = dateCreation;
	}
	
	public Investisseur getInvestisseur() {
		return this.investisseur;
	}

	public void setInvestisseur(Investisseur investisseur) {
		this.investisseur = investisseur;
	}
	
	public Set<Commentaire>  getCommentaires() {
		return this.commentaires;
	}

	public void setCommentaires(Set<Commentaire>  commentaires) {
		this.commentaires = commentaires;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setTitre(String titre) {
		this.titre = titre;
	}
	
	public String getTitre() {
		return titre;
	}
	
	public void setResume(String resume) {
		this.resume = resume;
	}
	
	public String getResume() {
		return resume;
	}
	
	public void setVisibilite(Visibilite visibilite) {
		this.visibilite = visibilite;
	}

	public Visibilite getVisibilite() {
		return visibilite;
	}
}
